//
//  FWFSViewController.m
//  Rong360
//
//  Created by tianliwei on 28/2/14.
//  Copyright (c) 2014 tianliwei. All rights reserved.
//

#import "FWFSViewController.h"
#import "DetailWebViewController.h"

@interface FWFSViewController ()
@property (nonatomic, strong)NSArray *yimains;
@property (nonatomic, strong)NSArray *jimains;
@property (nonatomic, strong)NSArray *yisubs;
@property (nonatomic, strong)NSArray *jisubs;
@end

@implementation FWFSViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"房屋风水";
    NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"fwfs" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    NSDictionary *yi = [dic objectForKey:@"good"];
    NSDictionary *ji = [dic objectForKey:@"bad"];
    self.yimains = [yi objectForKey:@"main"];
    self.jimains = [ji objectForKey:@"main"];
    self.yisubs = [yi objectForKey:@"sub"];
    self.jisubs = [ji objectForKey:@"sub"];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_NAVIFRAME_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.backgroundColor = RGBCOLOR(245, 245, 245);
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
}


#pragma mark - Table view data source


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 45;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
     UIView *v = nil;
    switch (section) {
        case 0:{
            v = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 30, 45)];
            v.backgroundColor = [UIColor whiteColor];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"list_yi"];
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(16, 44, 304, 1)];
            line.backgroundColor = RGBCOLOR(240, 240, 240);
            [v addSubview:line];
            [v addSubview:imageView];
            break;
        }
            
        case 1:{
            v = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 30, 45)];
            v.backgroundColor = [UIColor whiteColor];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"list_ji"];
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(16, 44, 304, 1)];
            line.backgroundColor = RGBCOLOR(240, 240, 240);
            [v addSubview:line];
            [v addSubview:imageView];
            break;
        }
        default:
            break;
    }
    return v;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return self.yimains.count;
        case 1:
            return self.jimains.count;
        default:
            break;
    }
    
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(16, 42, 304, 1)];
        line.backgroundColor = RGBCOLOR(240, 240, 240);
        [cell.contentView addSubview:line];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
    }
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = self.yimains[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            break;
        case 1:
            cell.textLabel.text = self.jimains[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            break;
        default:
            break;
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *detailStr = nil;
    self.hidesBottomBarWhenPushed = YES;
    switch (indexPath.section) {
        case 0:
            detailStr = self.yisubs[indexPath.row];
            break;
        case 1:
            detailStr = self.jisubs[indexPath.row];
        default:
            break;
    }
    DetailWebViewController *webVC = [[DetailWebViewController alloc]initWithContent:detailStr];
    [self.navigationController pushViewController:webVC animated:YES];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
